﻿CREATE PROCEDURE [ServiceEngine].[GetSchemabyNamespace]
	@Namespace nvarchar(400)
AS
BEGIN
	SET NOCOUNT ON;
	-- Namespace
	SELECT	N.[EntityID] as SchemaID, N.[EntityName] as [Name], N.EntityDescription as Description
	FROM	[ServiceEngine].Schemas S
	JOIN	[ServiceEngine].Names N on N.[EntityID] = S.SchemaID and N.[EntityTypeID] = 9
	WHERE	N.[EntityName] = @Namespace

	-- Imports
	SELECT 
		   SI.[SchemaImportID]
	      ,SI.[ImportNamespace]
  	FROM	[ServiceEngine].SchemaImports SI
	JOIN	[ServiceEngine].Names N on N.[EntityID] = SI.SchemaID and N.[EntityTypeID] = 9
	WHERE	N.[EntityName] = @Namespace

	-- Objects
	SELECT 
		   SO.[SchemaObjectID]
		  ,SO.[SchemaObjectName]
		  ,SO.[SchemaObjectType]
		  ,SO.[SchemaObjectXml]
  	FROM	[ServiceEngine].SchemaObjects SO
	JOIN	[ServiceEngine].Names N on N.[EntityID] = SO.SchemaID and N.[EntityTypeID] = 9
	WHERE	N.[EntityName] = @Namespace AND SO.DateRevised = NULL

END


